# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://doc.scrapy.org/en/latest/topics/item-pipeline.html
import json
import codecs


class MycwpjtPipeline(object):
    def __init__(self):
        self.file = codecs.open('test.json', 'wb', encoding='utf-8')

    def process_item(self, item, spider):
        if spider.name == 'weisuen':
            print('-' * 100)
            print(item)
            print('-' * 100)
            line = json.dumps(dict(item), indent=2, ensure_ascii=False) + ',\n'
            self.file.write(line)
            return item

    def close_spider(self, spider):
        if spider.name == 'weisuen':
            self.file.close()
